package com.um.jdy.common.charge.service.impl;


import com.um.jdy.common.charge.dao.OrderPlaceTimeDao;
import com.um.jdy.common.charge.entity.po.OrderEbPower;
import com.um.jdy.common.charge.entity.po.OrderPlaceTime;
import com.um.jdy.common.device.dao.FeePlaceDao;
import com.um.jdy.common.device.dao.FeePlaceTimeDao;
import com.um.jdy.common.device.entity.po.FeeEbPower;
import com.um.jdy.common.device.entity.po.FeePlace;
import com.um.jdy.common.device.entity.po.FeePlaceTime;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import com.um.springboot.starter.orm.service.BaseEntityServiceImpl;
import com.um.jdy.common.charge.service.OrderPlaceService;
import com.um.jdy.common.charge.dao.OrderPlaceDao;
import com.um.jdy.common.charge.entity.po.OrderPlace;

import java.util.Date;
import java.util.List;

/**
 * 服务实现类：订单副本-占位费表
 */
@Service
@Slf4j
public class OrderPlaceServiceImpl extends BaseEntityServiceImpl<OrderPlaceDao,OrderPlace>  implements OrderPlaceService{

    @Autowired
    FeePlaceDao feePlaceDao;

    @Autowired
    FeePlaceTimeDao feePlaceTimeDao;

    @Autowired
    OrderPlaceTimeDao orderPlaceTimeDao;

    /**
     * 添加订单占位副本
     *
     * @param feeId
     * @param orderId
     */
    @Override
    public void addPlaceAndTime(String feeId, String orderId) {
        FeePlace feePlace = feePlaceDao.getRow("device_fee_id",feeId);
        if(feePlace != null){
            OrderPlace orderPlace = new OrderPlace();
            BeanUtils.copyProperties(feePlace,orderPlace);
            orderPlace.setChargeOrderId(orderId);
            orderPlace.setCreateTime(new Date());
            this.saveRow(orderPlace);

            List<FeePlaceTime> times = feePlaceTimeDao.getRows(new String[]{"device_fee_id"},new Object[]{feeId},
                    new String[]{"start_time"},new String[]{"asc"});
            for(FeePlaceTime time : times){
                OrderPlaceTime orderPlaceTime = new OrderPlaceTime();
                BeanUtils.copyProperties(time,orderPlaceTime);
                orderPlaceTime.setChargeOrderId(orderId);
                orderPlaceTime.setCreateTime(new Date());
                orderPlaceTime.setChargeOrderPlaceTimeId(createUUIDPrimaryId());
                orderPlaceTimeDao.addRow(orderPlaceTime);
            }
        }
    }
}
